package com.hww.eam_pub;

import android.graphics.Point;
import android.os.Bundle;
import android.os.Handler;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;

import androidx.appcompat.app.AppCompatActivity;

import net.facelib.eam.module.EAMLaunch;
import net.facelib.eam.module.callback.temp.DeviceOnlineCallback;
import net.facelib.eam.module.info.DataInfo;
import net.facelib.eam.module.info.DeviceResolutionRatioDes;
import net.facelib.eam.module.info.LiveDataInfo;
import net.facelib.eam.module.utils.LogUtils;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        EAMLaunch.getInstance().initApp();

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                init();
            }
        }, 5 * 1000);
    }


    private void init() {

        DeviceResolutionRatioDes ratioDes = DeviceResolutionRatioDes.RATIO_1080_1920;

        RelativeLayout viewById = findViewById(R.id.main_layout);
        FrameLayout frameLayout = new FrameLayout(this);
        viewById.addView(frameLayout);
        ViewGroup.LayoutParams layoutParams = frameLayout.getLayoutParams();
        layoutParams.width = ratioDes.getWidth();
        layoutParams.height = ratioDes.getHeight();

        EAMLaunch.getInstance().initView(this, frameLayout, new Point(0, 0), ratioDes, new DeviceOnlineCallback() {
            @Override
            public void response(int i, String s, Object o) {
                LogUtils.e(String.format("DeviceOnlineCallback: status=%s\n%s\n%s", i, s, o));
            }

            @Override
            public void responseDTalk(int i, String s) {
                LogUtils.e(String.format("DeviceOnlineCallback:responseDTalk: status=%s\n%s", i, s));
            }
        });

        /*延时指定时间进行设备上线*/
        /**
         *  延时指定时间进行设备上线
         *
         * @param interval 延时执行任务的时间
         * @param msg 描述
         */
        DataInfo.getInstance().setLiveDateDeviceOnline(new LiveDataInfo(3, "device online"));

    }

}
